import { IRootState } from "@/store/types";
import { Module } from "vuex";
import { IEcharts } from "./type";
import { getGoodsCountRequest,getGoodsSaleRequest,getGoodsFavorRequest,getAddressSaleRequest} from '@/service/main/analysis/analysis'


const AnslysisModule:Module<IEcharts,IRootState> = {
    namespaced:true,
    state() {
        return{
            categoryGoodsCount:[],
            categoryGoodsFavor:[],
            categoryGoodsSale:[],
            addressGoodsSale:[]
        }
    },
    mutations:{
        changeGoodsCount(state,data){
            state.categoryGoodsCount = data
        },

        changeGoodsSale(state,data){
            state.categoryGoodsSale = data
        },

        changeGoodsFavor(state,data){
            state.categoryGoodsFavor = data
        },

        changeAddressSale(state,data){
            state.addressGoodsSale = data
        },

    },
    actions:{
        async getEchartDataAction({commit}){

           const GoodsCount = await getGoodsCountRequest()
           commit('changeGoodsCount',GoodsCount.data)

           const GoodsSale = await getGoodsSaleRequest()
           commit('changeGoodsSale',GoodsSale.data)

           const GoodsFavor = await getGoodsFavorRequest()
           commit('changeGoodsFavor',GoodsFavor.data)

           const AddressSale = await getAddressSaleRequest()
           commit('changeAddressSale',AddressSale.data)
            
        }
    }

}

export default AnslysisModule